package cornenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 此处不自定义类型，防止数据库占位符?替换为字符串，在mysql进行匹配时发生类型转换

// 定义常量
const (
	// 处理中
	TASK_HANDLE_STATUS_PROGRESS = iota

	// 处理完成
	TASK_HANDLE_STATUS_COMPLETED

	// 处理失败
	TASK_HANDLE_STATUS_FAILED
)

// 实现EnumInerface接口
type TaskHandleStatus struct {
	enum.Enum[int]
}

// TaskHandleStatus.GetInstance().GetDescMap()
func (e *TaskHandleStatus) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		TASK_HANDLE_STATUS_PROGRESS: {
			"desc":  "处理中",
			"sort":  1,
			"color": "#2F363C",
		},
		TASK_HANDLE_STATUS_COMPLETED: {
			"desc":  "完成",
			"sort":  2,
			"color": "#009688",
		},
		TASK_HANDLE_STATUS_FAILED: {
			"desc":  "失败",
			"sort":  3,
			"color": "#FF5722",
		},
	}
}

// 存储已经创建的实例
var taskHandleStatusInstanceCache = make(map[int]*TaskHandleStatus)

// 根据value获取枚举
func TaskHandleStatusByValue(value int) *TaskHandleStatus {
	if instance, exists := taskHandleStatusInstanceCache[value]; exists {
		return instance
	}
	e := &TaskHandleStatus{}
	enum.SetEnumInstance(&e.Enum, e, value)
	taskHandleStatusInstanceCache[value] = e
	return e
}

var TaskHandleStatusEnum *TaskHandleStatus = func() *TaskHandleStatus {
	e := &TaskHandleStatus{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
